﻿using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace FastMapper.Helpers
{
    public static class MemberInfoExtensions
    {
        public static  string GetFullPath(this MemberInfoNode memberInfoNode)
        {
            if (memberInfoNode == null)
                return null;
            return
                memberInfoNode.GetChild().Select(c => c.Name).Aggregate(
                    (memberInfo1, memberInfo2) => string.Format("{0}.{1}", memberInfo1, memberInfo2));
        }

        public static IEnumerable<MemberInfoNode> GetChild(this MemberInfoNode @this)
        {
            if (@this == null)
                return null;
            var result = new List<MemberInfoNode>();
            result.Add(@this);
            var child = @this.Child;
            while (child != null)
            {
                result.Add(child);
                child = child.Child;
            }
            return result;
        }
    }
}